/**
 * Mixin LoadingAnimation
 * 
 * 
 * @author David Lindkvist (david.lindkvist@shapeshift.se)
 */

PWF.mixin.LoadingAnimation = {

	showLoadingAnimation: function(/*float*/opacity) 
	{
		//hide if already visible
		this.hideLoadingAnimation();
		
		if(Object.isUndefined(opacity)) {
			opacity = 0.2;
		}
		
		var container = $(this.containerId);
		this.splash = new Element('div');
		
		//calculate loading img position
		var imgY = (this.height/2)-25;
		var imgX = (this.width/2)-25;

		var top = 0;
		var left = 0;
		
		//check if containing block is static, if so, calculate position on screen
		if(container.getStyle('position') != 'absolute')
		{
			top = container.cumulativeOffset().top;
			left = container.cumulativeOffset().left;
		}
		
		//set widget specific style
		this.splash.setStyle({
			height: container.getHeight()+'px',
			width: container.getWidth()+'px',
			opacity: opacity,
			position: 'absolute',
			left: left+'px',
			top: top+'px'
		});
		
		//insert splash
		container.insert(this.splash);
		
		//add loading style class
		this.splash.addClassName('widgetLoadingAnimation');
	},
	hideLoadingAnimation: function() 
	{
		if(!Object.isUndefined(this.splash))
		{
			try {
				this.splash.remove();
			} 
			catch (ex) {}
			
			this.splash = undefined;
		}
	}
};